<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>requestAnimationFrame</title>
    <style>
        #demo {
            width: 100px;
            height: 100px;
            position: absolute;
            left: 10px;
            top: 10px;
            background-color: aqua;
        }
    </style>
</head>
<body>
    <div id="demo"></div>

    <script>      
        let requestAnimationFrame = (function () {
            return window.reqeustAnimationFrame ||
                window.webkitRequestAnimationFrame || 
                window.mozRequestAnimationFrame ||
                window.oRequestAnimationFrame ||
                window.msRequestAnimationFrame ||
                function (callback) {
                    setTimeout(callback, 1000 / 60);
                }
        })();

        let demo = document.getElementById('demo');
        let posLeft = 10;
        let step = 1;

        function animation () {
            if (posLeft >= 1000) {
                step = -1;
            }
            else if (posLeft<=10) {
                step = 1;
            }

            posLeft += step;
            demo.style.left = posLeft + 'px';
            requestAnimationFrame(animation, demo);
        }

        animation();
        
    </script>
</body>
</html>